package com.mk.springboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/index.html").setViewName("/index");
        registry.addViewController("/login.html").setViewName("/login");

        // 用户模块
        registry.addViewController("/users.html").setViewName("/user/list");
        registry.addViewController("/user/edit.html").setViewName("/user/edit");
        registry.addViewController("/user/add.html").setViewName("/user/add");
        registry.addViewController("/user/foot.html").setViewName("/user/foot");

        // 文章类别模块
//        registry.addViewController("category.html").setViewName("/category/list");
        registry.addViewController("/category/edit.html").setViewName("/category/edit");
//        registry.addViewController("/category/add.html").setViewName("/category/add");

        // 博文板块模块
        registry.addViewController("plate.html").setViewName("/plate/list");
        registry.addViewController("/plate/edit.html").setViewName("/plate/edit");
        registry.addViewController("/plate/add.html").setViewName("/plate/add");
    }

    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocalResolver();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login.html", "/user/login", "/build/**", "/images/**", "/vendors/**", "/src/**");
    }
}

